<?php

session_start();

if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {

    header("Location: login.php");
}

//==========================================
//	ESCAPE DANGEROUS SQL CHARACTERS
//==========================================
//
include 'i_functions.php';
//
include 'i_ClaimInit.php';
//
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $ClaimID = $_GET['ClaimID'];
    //print "ClaimID=" . $ClaimID . "<br>";
    $ID = htmlspecialchars($ClaimID);

    //==========================================
    //	CONNECT TO THE LOCAL DATABASE
    //==========================================
    $user_name = "root";
    $pass_word = "haddons";
    $database = "PPI";
    $server = "127.0.0.1";

    $db_handle = mysql_connect($server, $user_name, $pass_word);
    $db_found = mysql_select_db($database, $db_handle);
    //
// get list of Lenders
//
    //$SelName = "Lender";
    /*$FileName = "PPI.lenders";
    $Columns = array("ID", "LenderName", "Address1", "Address2");
    $Options = array();
    $Options["Name"] = "Lender";
    $Options["OrderBy"] = "LenderName";
    $LenderSelect = SelectList($FileName, $Columns, $Options);*/

    $Options = array();
    $Options['TableName'] = "claims,client";
    $Options['ID'] = $ClaimID;
    $Options["Filter"] = "claims.ID = '" . $ID. "' AND client.ID = ClientID";
    $QHTML = BuildEnq("ClaimPPIQ.txt", $db_handle, $Options);
    
    if ($db_found && $ClaimID != "NEW") {

        $SQL = "SELECT * FROM claims WHERE ID = '$ID'";
        //print $SQL . "<br>";
        $result = mysql_query($SQL);
        $num_rows = mysql_num_rows($result);
        //====================================================
        //	CHECK TO SEE IF THE $result VARIABLE IS TRUE
        //====================================================
        if ($result) {
            include 'i_head.php';
            if ($num_rows > 0) {
                $db_field = mysql_fetch_assoc($result);
                /* foreach ($db_field as $key_name => $key_value) {
                  print $key_name . "=" . $key_value . "<BR>";
                  } */
                //$ID = $db_field['ID'];
                $ClientID = $db_field['ClientID'];
                $LenderID = $db_field['LenderID'];
                $LoanNo = $db_field['LoanNo'];
                $LoanStartDate = $db_field['LoanStartDate'];
                $LoanType = $db_field['LoanType'];
                switch($LoanType) {
                case "L":
                    $LoanType_L = "checked";
                    break;
                case "C":
                    $LoanType_C = "checked";
                    break;
                default:
                    $LoanType_M = "checked";
                    break;
                }
                $LoanAmount = $db_field['LoanAmount'];
                $LoanDuration = $db_field['LoanDuration'];
                include 'i_ClaimForm.php';
            } else {
                $message = "not found!";
                print $message;
            }
            include 'i_foot.html';
        }
    } else {
        //print "should be here<br>";
        include 'i_head.php';
        include 'i_ClaimForm.php';
        include 'i_foot.html';
    }
}
?>